//
//  BHMeCollectionBaseViewController.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/24.
//

import UIKit

class BHMeCollectionBaseViewController: BHBaseViewController {

    
    lazy var pageCycleView: CZPageView = {
        let view = CZPageView.init(frame: CGRect(x: 0, y: UIScreen.begainY, width: UIScreen.width, height: 46))
        view.backgroundColor = .white
        view.delegate = self
        let config = CZPageConfig.init()
        config.showLine = false
        config.nomalFont = .systemFont(ofSize: 14, weight: .medium)
        config.selectFont = .systemFont(ofSize: 14, weight: .bold)
        config.nomalColor = .color_666666
        config.selectColor = .color_333333
        config.itemSpace = 10
        config.leadingSpace = 10
        config.tralingSpace = 5
        config.divideScreenWidth = true
        
        view.config = config
        return view
    }()
    
    lazy var bigScrollView: UIScrollView = {
        let view = UIScrollView.init(frame: CGRect(x: 0, y: UIScreen.begainY+46, width: UIScreen.width, height: UIScreen.showHeight-46))
        view.isPagingEnabled = true
        view.showsVerticalScrollIndicator = false
        view.showsHorizontalScrollIndicator = false
        view.bounces = false
        view.isScrollEnabled = false
        view.rebuild()
        return view
    }()

    
    fileprivate let childNameArray = BHHomeManager.meCollectionArray
    fileprivate var childArray: [BHMeCollectionChildViewController] = []
    fileprivate var childrenVC: BHMeCollectionChildViewController!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        self.bh_navigationBar.title_label.text = "我的收藏"
        
        self.pageCycleView.itemArray = self.childNameArray
        self.view.addSubview(self.pageCycleView)
        self.view.addSubview(self.bigScrollView)
        self.pageCycleView.relationScrollView = self.bigScrollView
        self.configChild()
       
    }
    

    private func configChild() {
        for i in 0...self.childNameArray.count-1 {
            let vc = BHMeCollectionChildViewController.init()
            vc.childType = i+1
            self.childArray.append(vc)
            self.bigScrollView.addSubview(vc.view)
            vc.view.frame = CGRect(x: UIScreen.width*CGFloat(i), y: 0, width: UIScreen.width, height: UIScreen.showHeight-46)
            if i == 0 {
                self.childrenVC = vc
            }
        }
        self.bigScrollView.contentSize = CGSize(width: UIScreen.width*CGFloat(self.childNameArray.count), height: 0)
        self.bigScrollView.alwaysBounceVertical = false;
    }

}
extension BHMeCollectionBaseViewController: CZPageViewDelegate {
    func pageViewSelectdIndex(_ index: Int, with model: CZTopSegMentItemModel, with pageView: CZPageView) {
        self.childrenVC = self.childArray[index]
        self.childrenVC.begainRefresh()
    }
}
